In a future processor manufacturing technique, more and more processor cores may be integrated on a single chip. This type of processor integrating many processor cores is typically referred to as a many-core processor. If a task scheduling method using only operating system software is still adopted for scheduling a task of an operating system in a many-core processor environment, an efficiency bottleneck of the task scheduling may become a bottleneck of the entire system; and if a scheduling method using only hardware is adopted, a hardware system may become extremely complicated, which further increases hardware design and authentication difficulties, and may cause a problem that the system is completely incompatible with an existing system.
In the prior art, a Linux system is used as an example: In a single-core processor environment, a system task is managed by a run queue structure; each central processing unit (CPU) includes two run queue structures, that is, an active run queue and an expired run queue; each of the run queue structures includes a ready task queue with 140 priorities, a task in a ready state is inserted into a queue with a corresponding priority in the active run queue, and for each task, there is a time slice for deciding duration in which the task can be executed. When duration in which a task is executed exceeds a length of a time slice, the task is suspended and moved to a queue with a corresponding priority in the expired run queue, and the length of the time slice of the task and a priority of the task are recalculated in a moving process. If a queue with a priority in the active run queue is empty at present, a position of the queue with the corresponding priority in the active run queue is swapped with a position of a queue with the corresponding priority in the expired run queue, that is, a task in the queue with the corresponding priority in the expired run queue is moved into the active run queue. Each time task scheduling is required, the Linux system invokes a scheduler( ) function to traverse an active run queue of a corresponding CPU, and obtains a ready task with a highest priority in the active run queue and runs the ready task.
In a many-core processor, each processor core has its own run queue. When a task is created, the task is inserted into a run queue of a processor core. This may cause a task imbalance between processor cores. Therefore, it is necessary to perform load balancing on all the processor cores at intervals, so as to keep balance of task loads between the processor cores.
In this view, the inventor finds that, during the task scheduling implemented by the many-core processor, the prior art has at least the following problem:
An algorithm of load balancing is extremely complicated, and its execution time increases with a quantity of processor cores; in a future many-core processor, a time required for load balancing for a run queue may reduce running efficiency of a system; and each time a CPU invokes a scheduler( ) function, the system may lock the run queue, and in this case, each processor core needs to wait for a run queue resource. Therefore, frequent waiting of the system for a run queue resource also lowers process management efficiency in the system.